package ext.generic.integration.manually;

import java.util.List;

import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.DefaultObjectFormProcessor;
import com.ptc.core.components.forms.FormProcessingStatus;
import com.ptc.core.components.forms.FormResult;
import com.ptc.core.components.util.FeedbackMessage;
import com.ptc.core.ui.resources.FeedbackType;
import com.ptc.netmarkets.model.NmOid;
import com.ptc.netmarkets.util.beans.NmCommandBean;

import ext.generic.integration.sourcing.service.TwoLevelMaterialService;
import wt.org.WTPrincipal;
import wt.part.WTPart;
import wt.session.SessionHelper;
import wt.util.WTException;

public class SecondarymaterialsManuallyPublishProcessor extends DefaultObjectFormProcessor {
	public FormResult doOperation(NmCommandBean arg0, List<ObjectBean> arg1) throws WTException {
		FormResult formresult = new FormResult();
//		WTPrincipal curUser= SessionHelper.manager.getPrincipal();
//		SessionHelper.manager.setAdministrator();
		boolean flag = false;
		NmOid nmoid = arg0.getActionOid();
		if(nmoid != null) {
			WTPart currentPart = (WTPart) nmoid.getRefObject();
			if(currentPart != null){
				flag = TwoLevelMaterialService.releasePart(currentPart);
			}
		}
		FeedbackMessage feedbackmessage = null;
		if(flag){
			feedbackmessage = new FeedbackMessage(FeedbackType.SUCCESS, null, "二级物料发布成功", null, new String[] {});
		}else{
			feedbackmessage = new FeedbackMessage(FeedbackType.FAILURE, null, "二级物料发布失败", null, new String[] {});
		}
		formresult.addFeedbackMessage(feedbackmessage);
		return formresult;
	}
	

}
